//
//  KidsTests.m
//  KidsTests
//
//  Created by tengfei on 14/11/22.
//  Copyright (c) 2014年 90's Technology Co.Ltd. All rights reserved.
//

#import <UIKit/UIKit.h>
#import <XCTest/XCTest.h>

#import "LoginRequestData.h"
#import "LoginResponseData.h"
#import "RequestFactory.h"

#import "NSString+md5.h"
@interface KidsTests : XCTestCase

@end

@implementation KidsTests

- (void)setUp {
    [super setUp];
}

- (void)tearDown {
    [super tearDown];
}

- (void)testExample {
    UIImage * image = [UIImage imageNamed:@"photo_size"];
    NSData * data = UIImagePNGRepresentation(image);
    NSLog(@"%@",[data base64EncodedStringWithOptions:0]);
    XCTAssertTrue(data);
}
-(void)testLogin{
    XCTestExpectation * exception = [self expectationWithDescription:@"High Expectations"];
    
    LoginRequestData * data = [[LoginRequestData alloc]init];
    data.phone = @"18267108251";
    data.password  = [@"111111" md5];
    
    LoginResponseData * data1 = [[LoginResponseData alloc]init];
    
    [RequestFactory requestWithRequestData:data forResponseData:data1 complete:^(ResponseData *responseData, NSError *error) {
        NSLog(@"%@",responseData.info);
        NSLog(@"%ld",(long)responseData.result);
        NSLog(@"%@",error.localizedDescription);
        [exception fulfill];
    }];
    
    [self waitForExpectationsWithTimeout:100.0 handler:^(NSError* error) {
        if(error){
            NSLog(@"TImeout Error : %@",error);
        }
    }];
}

-(void)testloginaf{
     XCTestExpectation * exception = [self expectationWithDescription:@"High Expectation"];
    AFHTTPRequestOperationManager * manager = [[AFHTTPRequestOperationManager alloc]initWithBaseURL:nil];
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html"];
    [manager POST:@"http://114.215.169.134/chip/web/index.php?r=parents/login"
       parameters:@{@"data":@{@"phone" : @"15958137016",@"pwd" : [@"123456" md5]}}
          success:^(AFHTTPRequestOperation *operation, id responseObject) {
              NSLog(@"22222222%@",operation.responseString);
              NSParameterAssert(operation.responseString);
              [exception fulfill];
          }
          failure:^(AFHTTPRequestOperation *operation, NSError *error) {
              NSLog(@"%@",error.localizedDescription);
              NSLog(@"%@",operation.responseString);
              [exception fulfill];
          }];
    [self waitForExpectationsWithTimeout:100.0 handler:^(NSError* error) {
        if(error){
            NSLog(@"TImeout Error : %@",error);
        }
    }];

}
- (void)testPerformanceExample {
    // This is an example of a performance test case.
    [self measureBlock:^{
        // Put the code you want to measure the time of here.
    }];
}

@end
